(function() {
	var $ = require(L('$')), _ = require(L('_'));
	var accessTokenKey = Ti.App.Properties.getString('twitterAccessTokenKey');
	var accessTokenSecret = Ti.App.Properties.getString('twitterAccessTokenSecret');
	var Twitter = require('utils/twitter').Twitter;

	var win = Ti.UI.createWindow({
		backgroundColor : 'white'
	});
	win.open();

	var button = Ti.UI.createButton({
		title : 'Login via Twitter!'
	});
	win.add(button);
	$.click(button, function() {
		var client = Twitter({
			consumerKey : "mJ61wXFxWvvOkq7WRGZQQ",
			consumerSecret : "bPDFcy3ueANLsWJd7BsbIeKEVdG8bx4hq6dt9ySAAY",
			accessTokenKey : accessTokenKey,
			accessTokenSecret : accessTokenSecret
		});
		$.on('login', client, function(e) {
			if (e.success) {
				$.w('TT: ' + JSON.stringify(e));
				Ti.App.Properties.setString('twitterAccessTokenKey', e.accessTokenKey);
				Ti.App.Properties.setString('twitterAccessTokenSecret', e.accessTokenSecret);
				
				client.request("1/statuses/update.json", {
					status : 'test 123 123 123'
				}, 'POST', function(e) {
					alert(JSON.stringify(e));
				});
			} else {
				alert(e.error);
			}
		});
		client.authorize();
	});
})(this);
